﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Linq;
using System.Text;
using PatientManagement.DAL.Database;
using PatientManagement.DAL.Translators;
using PatientManagement.DAL.Interfaces;
using ObjectModels = PatientManagement.Common.ObjectModels;

namespace PatientManagement.DAL.DAL
{
    public class DrugDataLayer : IDrugDataLayer
    {
        public bool AddDrug(Drug drug)
        {
            try
            {
                using (var context = new PatientManagementDataContext())
                {
                    int result = context.AddDrug(drug.Name, drug.Effect, drug.Amount,
                        drug.Price, drug.Description, drug.AlertAmount);
                    return result != 0 ? false : true;
                }
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        public List<ObjectModels.Drug> SearchDrugByName(string name)
        {
            var result = new List<ObjectModels.Drug>();
            try
            {
                using (var context = new PatientManagementDataContext())
                {
                    List<GetDrugByNameResult> drugs = context.GetDrugByName(name).ToList();
                    return drugs.ToObjectModels();
                }
            }
            catch (Exception)
            {
                return result;
                throw;
            }
            throw new NotImplementedException();
        }

        public List<Drug> SearchDrugByQuantity(decimal quantity)
        {
            throw new NotImplementedException();
        }


        List<Drug> IDrugDataLayer.SearchDrugByName(string name)
        {
            throw new NotImplementedException();
        }
    }
}
